<template>
    <el-dialog destroy-on-close :title="title" :model-value="visible" :before-close="onClose" append-to-body
        :width="width + 'px'" :close-on-click-modal="false">
        <div class="container" :style="{ height: height ? height + 'px' : 'auto' }">
            <slot name="content"></slot>
        </div>
        <template #footer>
            <span class="dialog-footer">
                <el-button type="danger" @click="onClose"> {{ height }} {{ cancelButtonText }}</el-button>
                <el-button type="primary" @click="onConfirm">{{ confirmButtonText }}</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
interface DialogProps {
    title?: string,
    visible: boolean,
    width?: number,
    height?: number | undefined,
    cancelButtonText?: string,
    confirmButtonText?: string
}
withDefaults(defineProps<DialogProps>(), {
    title: '标题',
    visible: false,
    width: 600,
    height: undefined,
    cancelButtonText: '取消',
    confirmButtonText: '确定'
})
const emit = defineEmits(["onClose", "onConfirm"])

const onClose = () => {
    emit("onClose")
}

const onConfirm = () => {
    emit("onConfirm")
}
</script>

<style lang="scss" scope>
.container {
    overflow-x: initial;
    overflow-y: auto;
}

.el-dialog {
    border-top-left-radius: 7px !important;
    border-top-right-radius: 7px !important;

    .el-dialog__header {
        margin-right: 0px;
        border-top-left-radius: 7px !important;
        border-top-right-radius: 7px !important;
        background-color: #009688 !important;

        .el-dialog__title {
            color: #fff;
            font-size: 16px;
            font-weight: 600;
        }
    }

    .el-dialog__headerbtn {
        .el-dialog__close {
            color: #fff;
        }
    }

    .el-dialog__body {
        padding: 10px;
    }

    .el-dialog__footer {
        border-top: 1px solid #e8eaec !important;
        padding: 10px;
    }
}
</style>
